// ignore_for_file: non_constant_identifier_names

/*
 * @Descripttion: 
 * @version: 
 * @Author: 刘冰见
 * @Date: 2024-10-09 08:54:43
 * @LastEditors: 刘冰见
 * @LastEditTime: 2024-10-12 19:09:45
 */
import 'package:dio/dio.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:sousuoapp/common/auth.dart';
import 'package:sousuoapp/models/orderItem.dart';
import 'package:sousuoapp/net/method/bese_method.dart';
import 'package:sousuoapp/net/network_manager.dart';
import 'package:sousuoapp/net/response/base_response.dart';

class OrderController {
  getOrderList(data) async {
    BaseResponse response = await NetworkManager().request(
        '/phone_app/query_order_list',
        method: BaseMethod.post,
        data: data);
    if (response.code == 200) {
      final dataJson = response.data;
      if (dataJson['code'] == '1000') {
        final dynamic OrderitemJson = dataJson['data'] ?? [];

        final List<Orderitem> Orderitems =
            OrderitemJson.map<Orderitem>((e) => Orderitem.fromJson(e)).toList();
        return Orderitems;
      } else if (dataJson['code'] == '904') {
        final auth = Auth();
        auth.logout();
      } else {
        EasyLoading.dismiss();
        throw Exception(dataJson['msg'] ?? "failed to load Orderitems");
      }
    } else {
      EasyLoading.dismiss();
      throw Exception("failed to load Orderitems");
    }
  }

  cancelDeletOrder(data) async {
    BaseResponse response = await NetworkManager().request(
        '/phone_app/refund_cancel_order',
        method: BaseMethod.post,
        data: data);
    return response.data;
  }
}
